package com.rex.saas.service;

import com.rex.saas.bean.DeviceProfileBasicData;
import com.rex.saas.bean.request.CategoryAddRequest;
import com.rex.saas.bean.response.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName DeviceService
 * @Description:
 * @Author: zhusiyu
 * @CreateDate: 2024/12/18 11:06	//创建时间
 */
@Component
@Slf4j
public class CategoryService {

    @Autowired
    RexolarApiClient rexolarApiClient;

    public List<CategroyResponse> list(String token) {
        List<CategroyResponse> responseList = new ArrayList<>();
        Map<String, String> deviceProfilesMap = rexolarApiClient.getDeviceProfiles(token);
        for(String key : deviceProfilesMap.keySet()){
            CategroyResponse response = new CategroyResponse();
            response.setCategoryId(key);
            response.setCategoryName(deviceProfilesMap.get(key));
            responseList.add(response);
        }
        return responseList;
    }

    public CategroyResponse details(String token, String categoryId) {
        Map<String, String> deviceProfilesMap = rexolarApiClient.getDeviceProfiles(token);
        for(String key : deviceProfilesMap.keySet()){
            if(key.equals(categoryId)){
                CategroyResponse response = new CategroyResponse();
                response.setCategoryId(key);
                response.setCategoryName(deviceProfilesMap.get(key));
                return response;
            }
        }
        return null;
    }

    public String add(String token, CategoryAddRequest categoryAddRequest) {
        return rexolarApiClient.dynamicAddCategory(token, categoryAddRequest);
    }

    public CategroyResponse getDetailsByName(String token, String name) {
        Map<String, String> deviceProfilesMap = rexolarApiClient.getDeviceProfiles(token);
        for(String key : deviceProfilesMap.keySet()){
            if(deviceProfilesMap.get(key).equals(name)){
                CategroyResponse response = new CategroyResponse();
                response.setCategoryId(key);
                response.setCategoryName(deviceProfilesMap.get(key));
                return response;
            }
        }
        return null;
    }
    public DeviceProfileBasicData getDetailsById(String token, String getDeviceProfileById) {
        return rexolarApiClient.getDeviceProfileById(token, getDeviceProfileById);
    }
}
